package cloudInformation.controller;

import cloudEntity.utils.ResultUtils;
import cloudEntity.vo.PageBeanVO;
import cloudEntity.dto.dorm.SmartDormFloorInsertDTO;
import cloudEntity.vo.dorm.SmartDormFloorVO;
import cloudEntity.dto.dorm.SmartDormFloorUpdateDTO;
import cloudInformation.service.SmartDormFloorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: Smart School
 * @ClassName DormFloorController
 * @description: 楼层 控制器
 * @author: 陈智博
 * @create: 2025-05-17 10:27
 * @Version 1.0
 **/
@RestController
@RequestMapping("/dorm/floor")
@Tag(name="楼层控制器")
public class DormFloorController {

    @Autowired
    private SmartDormFloorService smartDormFloorService;

    @Operation(summary = "分页获取楼层信息")
    @Parameters({
            @Parameter(name = "t",description = "楼层名字",required = false),
            @Parameter(name = "n",description = "页码",required = false),
            @Parameter(name = "s",description = "条数",required = false)
    })
    @RequestMapping(method = RequestMethod.GET,value = "/page")
    public ResultUtils GetDormFloorPage(@RequestParam(value = "t",required = false,defaultValue = "") String dormFloorName,
                                    @RequestParam(value = "n",required = false,defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "s",required = false,defaultValue = "5") Integer pageSize)
    {
        PageBeanVO<SmartDormFloorVO> smartNewsDTOPageBeanVO = smartDormFloorService.GetDormFloorByPage(dormFloorName, pageNum, pageSize);
        return ResultUtils.success(smartNewsDTOPageBeanVO);
    }

    @Operation(summary = "新增楼层信息")
    @Parameter(name = "smartDormFloorInsertDTO",description = "楼层新增DTO",required = true)
    @RequestMapping(method = RequestMethod.POST,value = "/insert")
    public ResultUtils InsertDormFloor(@RequestBody SmartDormFloorInsertDTO smartDormFloorInsertDTO)
    {
        Integer i =  smartDormFloorService.InsertDormFloor(smartDormFloorInsertDTO);
        if(i>0)
        {
            return ResultUtils.success("新增记录成功!");
        }
        return ResultUtils.failed("新增记录失败!");
    }

    @Operation(summary = "修改楼层信息")
    @Parameter(name = "smartDormFloorInsertDTO",description = "楼层修改DTO")
    @RequestMapping(method = RequestMethod.PUT,value = "/update")
    public ResultUtils UpdateDormFloor(@RequestBody SmartDormFloorUpdateDTO smartDormFloorUpdateDTO)
    {
        Integer i = smartDormFloorService.UpdateDormFloor(smartDormFloorUpdateDTO);
        if(i>0)
        {
            return ResultUtils.success("修改记录成功!");
        }
        return ResultUtils.failed("修改记录失败!");
    }

}
